package com.sgb.kjwl.view.ui.activity.logistics;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.PersistableBundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLogisticsSreach3Binding;
import com.sgb.kjwl.di.home.DaggerHomeComponent;
import com.sgb.kjwl.di.home.HomeModule;
import com.sgb.kjwl.view.ui.fragment.freightTransport.LogisticsSearchListFragment3;
import com.sgb.kjwl.viewmodel.home.SearchModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

import javax.inject.Inject;

/**
 * Description:
 * Author CFK
 * Time
 */
public class LogisticsSearchActivity3 extends AppActivity {
    private ActivityLogisticsSreach3Binding binding;
    private String[] titles = {"找货", "找车"};
    private SlidingFragmentPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    @Inject
    SearchModel3 viewModel;

    public static void start(Context context, int type) {
        Intent intent = new Intent();
        intent.putExtra("type", type);
        intent.setClass(context, LogisticsSearchActivity3.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerHomeComponent.builder().appComponent(appComponent).homeModule(new HomeModule(this)).build().inject(this);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(LogisticsSearchActivity3.this, R.layout.activity_logistics_sreach3);
        binding.ivBack.setOnClickListener(this);
        binding.etView.setOnClickListener(this);
        mFragments = new ArrayList<>();
        mFragments.add(LogisticsSearchListFragment3.newInstance(2));
        mFragments.add(LogisticsSearchListFragment3.newInstance(1));
        pagerAdapter = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(2);
        binding.tabLayout.setupWithViewPager(binding.viewpager);


    }


    @Override
    protected void init() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
